//
//  FPLoanDetailModel.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/2/11.
//

#import "FPLoanDetailModel.h"

@implementation FPRepaymentSummary

@end


@implementation FPRepaymentSchedules

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}

@end



@implementation FPLoanDetailListModel

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}

+ (void)getUserCurrenMonthLoan:(NSDictionary *)param success:(void (^)(NSInteger code , NSString *message , FPLoanDetailListModel *model))success failure:(void (^)(NSError *error))failure {
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:CURREN_MONTH_LOAN_URL] parameters:param type:HttpRequestTypeGet success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
        FPLoanDetailListModel *model = [[FPLoanDetailListModel alloc] initWithDictionary:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , model);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}




@end













@implementation FPLoanDetailModel

+ (JSONKeyMapper *)keyMapper {
    
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"ID" : @"id"}];
}

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
}


+ (void)getRepayMentSuccess:(void (^)(NSInteger, NSString * _Nonnull, FPLoanDetailModel *))success failure:(void (^)(NSError * _Nonnull))failure {
    
//    NSMutableDictionary *param = APIClient.creatAPIDictionary;
    
//    [param setObject:ID forKey:@"loanId"];
//    [param setObject:status forKey:@"status"];
//    
//    NSString *urlStr = [APIClient getQueryURLStringWithParam:param URLString:LOAN_DETAIL_URL];
    
    
    
    [[APIClient sharedInstance] requestWithURLString:[MAIN_URL stringByAppendingString:LOAN_DETAIL_URL_V2] parameters:@{} type:HttpRequestTypeGet success:^(id responseObject, NSString *msg, NSInteger code) {
        
        NSError *error;
        
        id object = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:&error];
        
//        NSArray *list = [FPLoanDetailModel arrayOfModelsFromDictionaries:[object objectForKey:@"data"] error:&error];
        FPLoanDetailModel *model = [[FPLoanDetailModel alloc] initWithDictionary:[object objectForKey:@"data"] error:&error];
        
        NSInteger httpCode = [[object objectForKey:@"code"] integerValue];
        
        NSString *message = [object objectForKey:@"msg"];
        
        if (success) {
            
            success(httpCode , message , model);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}


+ (NSString *)termOfParam:(NSString *)param {
    
    NSString *text;
    
    // 借款期限（期数）0.3个月,1.6个月,2.9个月,3.12个月,4.24个月
    switch (param.integerValue) {
        case 0:
            text = @"3";
            break;
            
        case 1:
            text = @"6";
            break;
            
        case 2:
            text = @"9";
            break;
            
        case 3:
            text = @"12";
            break;
            
        case 4:
            text = @"24";
            break;
            
        default:
            break;
    }
    
    return text;
}

+ (NSString *)timeOfParam:(NSString *)param {
    
    NSArray *temp = [param componentsSeparatedByString:@" "];
    
    return temp.firstObject;
}



@end
